package com.doit.day01;

import java.util.*;

/**
 * 迭代器：是从一个数据存储系统中迭代获取数据的工具
 *
 * 他屏蔽了取数据的底层细节
 * 暴露给用户的是统一的取数据的方式：hasNext   next
 */

//需求：需要你们自己写一个迭代器，将这个文件中的数据取出来，然后返回给用户一个User对象
public class Test {
    public static void main(String[] args) throws Exception {
      /*  //数组
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);

        Iterator<Integer> iterator = list.iterator();
        while (iterator.hasNext()){
            Integer i = iterator.next();
            System.out.println(i);
        }


        //hash表
        HashSet<Integer> set = new HashSet<>();
        set.add(1);
        set.add(2);
        set.add(3);
        set.add(4);

        Iterator<Integer> it = set.iterator();
        while (it.hasNext()){
            Integer num = it.next();
            System.out.println(num);
        }*/
// 从文件中获取数据
/*        MyIterator myIterator = new MyIterator();
        while (myIterator.hasNext()){
            System.out.println(myIterator.next());
        }*/
        //从mysql中获取数据
/*        MysqlIterator mysqlIterator = new MysqlIterator();
        while (mysqlIterator.hasNext()){
            System.out.println(mysqlIterator.next());
        }*/

        //测试MyIterable
//        MyIterable heroes = new MyIterable();
/*        Iterator<Hero> iterator = heroes.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }*/

/*
        for (Hero hero : heroes) {
            System.out.println(hero);
        }
*/

        ArrayList<Hero> list = new ArrayList<>();
        list.add(new Hero(1,"zss",18,100));
        list.add(new Hero(3,"lss",28,110));
        list.add(new Hero(2,"ww",8,150));
        list.add(new Hero(5,"zl",58,120));
        list.add(new Hero(4,"tq",48,130));


        //将上面的list排序
/*        Collections.sort(list,new MyComparator());

        for (Hero hero : list) {
            System.out.println(hero);
        }*/

        Collections.sort(list);
        for (Hero hero : list) {
            System.out.println(hero);
        }


/*        ArrayList<Integer> nums = new ArrayList<>();
        nums.add(1);
        nums.add(3);
        nums.add(4);
        nums.add(2);
        nums.add(7);
        Collections.sort(nums);//并没有要求我们传一个比较器
        System.out.println(nums);//因为我们int类型它本身是可比较的*/


    }
}

//对年龄进行排序
class MyComparator implements Comparator<Hero>{

    @Override
    public int compare(Hero o1, Hero o2) {
        return o1.getAge() - o2.getAge();
    }
}
